class UserModel {
  int id;
  String name;
  String username;
  String password;
  String email;
  int creatorId;
  int departmentId;
  int status;
  String lastLoginIp;
  int lastLoginTime;
  String createTime;
  String updateTime;
  int deleteTime;
  List<Roles> roles;
  List<int> departmentArr;

  UserModel(
      {this.id,
      this.name,
      this.username,
      this.password,
      this.email,
      this.creatorId,
      this.departmentId,
      this.status,
      this.lastLoginIp,
      this.lastLoginTime,
      this.createTime,
      this.updateTime,
      this.deleteTime,
      this.roles,
      this.departmentArr});

  UserModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    username = json['username'];
    password = json['password'];
    email = json['email'];
    creatorId = json['creator_id'];
    departmentId = json['department_id'];
    status = json['status'];
    lastLoginIp = json['last_login_ip'];
    lastLoginTime = json['last_login_time'];
    createTime = json['create_time'];
    updateTime = json['update_time'];
    deleteTime = json['delete_time'];
    if (json['roles'] != null) {
      roles = new List<Roles>();
      json['roles'].forEach((v) {
        roles.add(new Roles.fromJson(v));
      });
    }
    departmentArr = json['department_arr'].cast<int>();
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['name'] = this.name;
    data['username'] = this.username;
    data['password'] = this.password;
    data['email'] = this.email;
    data['creator_id'] = this.creatorId;
    data['department_id'] = this.departmentId;
    data['status'] = this.status;
    data['last_login_ip'] = this.lastLoginIp;
    data['last_login_time'] = this.lastLoginTime;
    data['create_time'] = this.createTime;
    data['update_time'] = this.updateTime;
    data['delete_time'] = this.deleteTime;
    if (this.roles != null) {
      data['roles'] = this.roles.map((v) => v.toJson()).toList();
    }
    data['department_arr'] = this.departmentArr;
    return data;
  }
}

class Roles {
  int id;
  String roleName;
  int parentId;
  String description;
  int dataRange;
  int creatorId;
  String createTime;
  String updateTime;
  int deleteTime;
  Pivot pivot;

  Roles(
      {this.id,
      this.roleName,
      this.parentId,
      this.description,
      this.dataRange,
      this.creatorId,
      this.createTime,
      this.updateTime,
      this.deleteTime,
      this.pivot});

  Roles.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    roleName = json['role_name'];
    parentId = json['parent_id'];
    description = json['description'];
    dataRange = json['data_range'];
    creatorId = json['creator_id'];
    createTime = json['create_time'];
    updateTime = json['update_time'];
    deleteTime = json['delete_time'];
    pivot = json['pivot'] != null ? new Pivot.fromJson(json['pivot']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['role_name'] = this.roleName;
    data['parent_id'] = this.parentId;
    data['description'] = this.description;
    data['data_range'] = this.dataRange;
    data['creator_id'] = this.creatorId;
    data['create_time'] = this.createTime;
    data['update_time'] = this.updateTime;
    data['delete_time'] = this.deleteTime;
    if (this.pivot != null) {
      data['pivot'] = this.pivot.toJson();
    }
    return data;
  }
}

class Pivot {
  int id;
  int uid;
  int roleId;

  Pivot({this.id, this.uid, this.roleId});

  Pivot.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    uid = json['uid'];
    roleId = json['role_id'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['uid'] = this.uid;
    data['role_id'] = this.roleId;
    return data;
  }
}
